package com.vf.admin.miaodong.controller;

import com.vf.admin.client.service.AppSpouseClerkService;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppSpouseClerk;
import com.vf.admin.utils.StringEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/after/spouse")
public class AfterSpouseClerkController extends BaseController {

    @Autowired
    private AppSpouseClerkService appSpouseClerkService;

    /**
     * 获取夫妻相匹配文案列表
     * @param splitPageBean
     * @param appSpouseClerk
     * @return
     */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean, AppSpouseClerk appSpouseClerk)
    {
        List<AppSpouseClerk> list = appSpouseClerkService.getList(splitPageBean, appSpouseClerk);
        request.setAttribute("list",list);
        request.setAttribute("splitPageBean",splitPageBean);
        request.setAttribute("appSpouseClerk",appSpouseClerk);
        return this.sucess("/web/after/spouse/list");
    }

    /**
     * 添加或修改夫妻相匹配文案页面
     * @param appSpouseClerk
     * @return
     */
    @RequestMapping("/addOrEdit")
    public String addOrEdit(AppSpouseClerk appSpouseClerk)
    {
        if(StringEx.isNullOrLing(appSpouseClerk.getId())){
            return this.sucess("/web/after/spouse/addOrEdit");
        }else{
            AppSpouseClerk clerkById = appSpouseClerkService.getClerkById(appSpouseClerk.getId());
            request.setAttribute("info",clerkById);
            return this.sucess("/web/after/spouse/addOrEdit");
        }
    }


    /**
     * 添加或修改夫妻相匹配
     * @param appSpouseClerk
     * @return
     */
    @ResponseBody
    @RequestMapping("/addOrEditDo")
    public Result addOrEditDo(AppSpouseClerk appSpouseClerk)
    {
        appSpouseClerkService.addOrEdit(appSpouseClerk);
        return this.sucessJSON("操作成功");
    }



}
